<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        th,td{
            border:1px solid #000000;
            width: 80px;
            text-align: center;
        }
    </style>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery.min.js"></script>
</head>
<body>
<% if(state==1){%>
<form action="/users/search" method="post">
    账号：<input type="text" name="username"><br>
    状态：<input type="checkbox" name="state" value="1"><br>

    <input type="submit" value="查询">
</form>
<a href="/users/add">新增</a>
<%}%>
<hr>
 欢迎您<%=user%> <a href="/users/logout">注销</a>

<table style="border:1px solid #000000; border-collapse: collapse">
    <tr>
        <th>编号</th>
        <th>账号</th>
        <th>密码</th>
        <th>真实姓名</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    <%if(rows.length==0){%>
    <tr>
        <td colspan="6">没有查询到记录</td>
    </tr>
    <%}else{%>
    <% rows.forEach(function(item){%>
    <tr>
        <td><%=item.id%></td>
        <td><%=item.username%></td>
        <td><%=item.password%></td>
        <td><%=item.realname%></td>
        <td>
            <%=item.state%>
        </td>
        <td>
            <% if(state==1){%>
            <a onclick="return confirm('确定要删除吗？');" href="/users/del/<%=item.id%>">删除</a>
            <!-- <a onclick="if(confirm('确定删除该条数据')){del(<%=item.id %>);}">删除</a> -->
            <%}%>
            <a href="/users/update/<%=item.id%>">修改</a>
        </td>
    </tr>
    <%});
    }%>
</table>
<% if(flag==1){%>
<nav aria-label="Page navigation example">
    <ul class="pagination">
        <%if(page==1){%>
        <li class="page-item disabled"><a class="page-link" href="#">&laquo;</a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users?page=<%= page-1 %>">&laquo;</a></li>
        <%}%>
        <% for (let i=1; i<=Math.ceil(count/3); i++ ){
            if(i==page){
            %>
            <li class="page-item active"><a class="page-link" href="/users?page=<%= i %>"><%= i %></a></li>
            <%}else{%>
            <li class="page-item"><a class="page-link" href="/users?page=<%= i %>"><%= i %></a></li>
            <%  }
        }%>
        <%if(page==Math.ceil(count/3)){%>
        <li class="page-item disabled"><a class="page-link" href="#">&raquo;</a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users?page=<%= parseInt(page)+1 %>">&raquo;</a></li>
        <%}%>
    </ul>
</nav>
<%}%>
<% if(flag==2){%>
<% if(p==1) {%>
<nav aria-label="Page navigation example">
    <ul class="pagination">
        <%if(page==1){%>
        <li class="page-item disabled"><a class="page-link" href="#">&laquo;</a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users/search?page=<%= page-1 %>&p=1">&laquo;</a></li>
        <%}%>
        <% for (let i=1; i<=Math.ceil(count/3); i++ ){
        if(i==page){
        %>
        <li class="page-item active"><a class="page-link" href="/users/search?page=<%= i %>&p=1"><%= i %></a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users/search?page=<%= i %>&p=1"><%= i %></a></li>
        <%  } }%>
        <%if(page==Math.ceil(count/3)){%>
        <li class="page-item disabled"><a class="page-link" href="#">&raquo;</a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users/search?page=<%= parseInt(page)+1 %>&p=1">&raquo;</a></li>
        <%}%>
    </ul>
</nav>
<%}else if(p!=0){%>
<nav aria-label="Page navigation example">
    <ul class="pagination">
        <%if(page==1){%>
        <li class="page-item disabled"><a class="page-link" href="#">&laquo;</a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users/search?page=<%= page-1 %>&p=0">&laquo;</a></li>
        <%}%>
        <% for (let i=1; i<=Math.ceil(count/3); i++ ){
        if(i==page){
        %>
        <li class="page-item active"><a class="page-link" href="/users/search?page=<%= i %>&p=0"><%= i %></a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users/search?page=<%= i %>&p=0"><%= i %></a></li>
        <%  } }%>
        <%if(page==Math.ceil(count/3)){%>
        <li class="page-item disabled"><a class="page-link" href="#">&raquo;</a></li>
        <%}else{%>
        <li class="page-item"><a class="page-link" href="/users/search?page=<%= parseInt(page)+1 %>&p=0">&raquo;</a></li>
        <%}%>
    </ul>
</nav>
<%}
    }%>
</body>
</html>